package com.jarvis.plugin.dataredis.prefix.plugin;

import com.jarvis.core.interceptor.Interceptor;
import com.jarvis.core.plugin.AbstractPluginDefine;
import com.jarvis.plugin.dataredis.prefix.interceptor.DataredisPrefixInterceptor;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.ElementMatchers;

import static net.bytebuddy.matcher.ElementMatchers.named;

/**
 * @author xuxukang
 * @date 2019-07-05 15:55
 */
public class DataredisPrefixPlugin extends AbstractPluginDefine {

  @Override
  public Interceptor[] interceptors() {
    return new Interceptor[]{
      new Interceptor() {
        @Override
        public ElementMatcher<MethodDescription> methodMatcher() {
          return named("rawKey");
        }

        @Override
        public Class<?> getInterceptClass() {
          return DataredisPrefixInterceptor.class;
        }
      }
    };
  }

  @Override
  public ElementMatcher<? super TypeDescription> typeMatcher() {
    return ElementMatchers.isAbstract().and(named("org.springframework.data.redis.core.AbstractOperations"));
  }

  @Override
  public String pluginName() {
    return "springboot-dataredis-prefix";
  }
}
